//
//  SDHSportsPlayerInfoHeader.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/13.
//

#import "SDHSportsPlayerInfoHeader.h"
#import "SDHSportsPlayerInfoModel.h"
#import "UIImageView+YQAdd.h"

@interface SDHSportsPlayerInfoHeader ()

@property (nonatomic, strong) UILabel *weightLb;
@property (nonatomic, strong) UILabel *heightLb;
@property (nonatomic, strong) UIImageView *avatarImg;
@property (nonatomic, strong) UILabel *nameLb;

@end

@implementation SDHSportsPlayerInfoHeader

- (id)init {
    if (self = [super init]) {
        [self initUI];
    }
    
    return self;
}

- (void)initUI {
    UIView *hView = [UIView new];
    hView.backgroundColor = [UIColor whiteColor];
    hView.clipsToBounds = YES;
    hView.layer.cornerRadius = 5;
    hView.backgroundColor = [UIColor whiteColor];
    [self addSubview:hView];
    
    [hView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(kPlayInfoTableHeaderHeight);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.width.mas_equalTo(self.width-20);
    }];
    
    UIView *infoView = [UIView new];
    [hView addSubview:infoView];
    
    UILabel *weightLb = [UILabel new];
    weightLb.textAlignment = NSTextAlignmentLeft;
    weightLb.font = [UIFont systemFontOfSize:15];
    weightLb.backgroundColor = UIColorFromRGB(231, 231, 231);
    weightLb.textColor = [UIColor blackColor];
    weightLb.clipsToBounds = YES;
    weightLb.layer.cornerRadius = 15;
    [infoView addSubview:weightLb];
    self.weightLb = weightLb;
    NSMutableParagraphStyle *style =  [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.alignment = NSTextAlignmentJustified;
    style.firstLineHeadIndent = 8;
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:@"70kg" attributes:@{ NSParagraphStyleAttributeName : style}];
    weightLb.attributedText = attrText;
    
    UILabel *heightLb = [UILabel new];
    heightLb.textAlignment = NSTextAlignmentRight;
    heightLb.font = [UIFont systemFontOfSize:15];
    heightLb.backgroundColor = UIColorFromRGB(231, 231, 231);
    heightLb.textColor = [UIColor blackColor];
    heightLb.clipsToBounds = YES;
    heightLb.layer.cornerRadius = 15;
    [infoView addSubview:heightLb];
    self.heightLb = heightLb;
    style =  [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.alignment = NSTextAlignmentJustified;
    style.tailIndent = -3;
    style.alignment = NSTextAlignmentRight;
    attrText = [[NSAttributedString alloc] initWithString:@"1.85m" attributes:@{ NSParagraphStyleAttributeName : style}];
    heightLb.attributedText = attrText;
    
    UIImageView *imgView = [UIImageView new];
    imgView.image = [UIImage imageNamed:@"touxiang"];
    imgView.clipsToBounds = YES;
    imgView.layer.cornerRadius = 35;
    [infoView addSubview:imgView];
    self.avatarImg = imgView;
    
    UILabel *nameLb = [UILabel new];
    nameLb.textAlignment = NSTextAlignmentCenter;
    nameLb.textColor = [UIColor blackColor];
    nameLb.font = [UIFont boldSystemFontOfSize:18];
    [hView addSubview:nameLb];
    self.nameLb = nameLb;
    nameLb.text = @"Marcus Rashford";
    
    [infoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(20);
        make.width.mas_equalTo(160);
        make.height.mas_equalTo(70);
    }];
    
    [weightLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(80);
    }];
    
    [heightLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(80);
    }];
    
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(70);
    }];
    
    [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.equalTo(infoView.mas_bottom).offset(15);
    }];
}

- (void)updateContent:(SDHSportsPlayerInfoModel *)model {
    NSMutableParagraphStyle *style =  [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.alignment = NSTextAlignmentJustified;
    style.firstLineHeadIndent = 8;
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:@"70kg" attributes:@{ NSParagraphStyleAttributeName : style}];
    self.weightLb.attributedText = attrText;
    
    NSString *height = [NSString stringWithFormat:@"%@m", model.height];
    style =  [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.alignment = NSTextAlignmentJustified;
    style.tailIndent = -3;
    style.alignment = NSTextAlignmentRight;
    attrText = [[NSAttributedString alloc] initWithString:height attributes:@{ NSParagraphStyleAttributeName : style}];
    self.heightLb.attributedText = attrText;
    
    self.nameLb.text = model.name;
    [self.avatarImg setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"touxiang"]];
}

@end
